package com.tmall.tmall.controller.admin;

import com.tmall.tmall.pojo.PageRt;
import com.tmall.tmall.pojo.Result;
import com.tmall.tmall.pojo.Slideshow;
import com.tmall.tmall.service.SlideshowService;
import io.swagger.models.auth.In;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/slideshow")
public class AdminSlideshowController {
    @Autowired
    private SlideshowService slideshowService;

    /**
     * 增加
     * @param slideshow
     * @return
     */
    @PostMapping("/add")
    public Result add(@RequestBody Slideshow slideshow){
        slideshowService.insert(slideshow);
        return Result.success();
    }

    /**
     * 分页查询
     * @param pageNum
     * @param pageSize
     * @param title
     * @return
     */
    @GetMapping("/page")
    public Result page(@RequestParam(defaultValue = "1") Integer pageNum,
                       @RequestParam(defaultValue = "10") Integer pageSize,
                       String title){
        PageRt pageRt = slideshowService.page(pageNum,pageSize,title);
        return Result.success(pageRt);
    }

    /**
     * 修改
     * @param slideshow
     * @return
     */
    @PutMapping("/update")
    public Result update(@RequestBody Slideshow slideshow){
        slideshowService.update(slideshow);
        return Result.success();
    }

    /**
     * 删除
     * @param ids
     * @return
     */
    @DeleteMapping("/delBatch")
    public Result delete(@RequestBody List<Integer> ids){
        slideshowService.delete(ids);
        return Result.success();
    }

    /**
     * 查询所有
     * @return
     */
    @GetMapping("/list")
    public Result list(){
        List<Slideshow>list = slideshowService.selectAll();
        return Result.success(list);
    }
}
